import pointApi from '../../api/pointApi'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid: '',
    avatarUrl: '',
    nickname: '',
    historyList: [],
    count: 0
  },

  selectHead() {
    this.selectComponent('#avatarNickname').open()
  },

  avatarNicknameConfirm(e) {
    this.setData({
      avatarUrl: e.detail.avatarUrl,
      nickname: e.detail.nickname,
    })
  },

  toBaijia() {
    wx.navigateTo({
      url: '/pages/category/category',
    })
  },
  toReward() {
    wx.navigateTo({
      url: '/pages/reward/reward',
    })
  },
  toAdmin() {
    wx.navigateTo({
      url: '/pages/admin/admin',
    })
  },

  toBook: function (e) {
    var index = e.currentTarget.dataset.index;
    var history = this.data.historyList[index];
    var bookId = history.bookId;
    var pageNum = history.pageNum;
    wx.navigateTo({
      url: '../../book/book/book?id=' + bookId + '&pageNum=' + pageNum
    })
  },

  tipPoint() {
    wx.showModal({
      title: '提示',
      content: '积分可通过发布钓点和评论钓点获取',
      success(res) {

      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.setData({
      openid: wx.getStorageSync('openid')
    })



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    this.getTabBar().setData({
      selected: 2
    })

    let a = wx.getStorageSync('avatarUrl')
    let n = wx.getStorageSync('nickname')
    if (a) {
      this.setData({
        avatarUrl: a,
        nickname: n
      })
    }


    let res = await pointApi.get({
      openid: wx.getStorageSync('openid')
    })
    if (res) {
      this.setData({
        count: res.count
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})